<template>
  <div class="cart">
    <h2>购物车</h2>
    <div v-for="item in cartItems" :key="item.id">
      {{ item.name }} - ¥{{ item.price }} - 数量：{{ item.quantity }}
      <button @click="increment(item.id)">+</button>
      <button @click="decrement(item.id)">-</button>
    </div>
    <p>总价：¥{{ cartTotalPrice }}</p>
  </div>
</template>

<script>
import { mapState, mapGetters, mapActions } from 'vuex';

export default {
  computed: {
    ...mapState(['cartItems']),
    ...mapGetters(['cartTotalPrice'])
  },
  methods: {
    ...mapActions(['increment', 'decrement'])
  }
}
</script>

<style scoped>
.cart {
  text-align: center;
}
</style>